//
//  ViewController.m
//  03-UIResponder
//
//  Created by 王道林 on 16/7/18.
//  Copyright © 2016年 王道林. All rights reserved.
//

#import "ViewController.h"
#import "TouchView.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    TouchView *touchView = [[TouchView alloc] initWithFrame:CGRectMake(10, 10, 355, 200)];
    touchView.backgroundColor = [UIColor redColor];
    [self.view addSubview:touchView];
    
    // 1. 响应者链
    // 检测顺序: 硬件 -> Appdelegate -> UIApplication -> UIWindow -> UIViewController -> self.view -> TouchView
    // 相应顺序 :   touchView -> self.view -> UIViewcontroller -> UIWindow ->UIApplication ->Appdelegate ->null
    // 如果所有的响应者都无法相应事件, 则这个事件会被舍弃
    // 俩种检测响应者的方法
    // 1. Categary 实现touchBegin
    // 2. nextResponder
    
    // 例 :
    // 1 . 响应者不要出父视图的边界, 出边界的响应者无法响应
    //     判断当前的点,在谁的范围内
   BOOL isInside = [touchView pointInside:CGPointMake(10, 20) withEvent:nil];
    NSLog(@"%@", isInside ? @"YES" : @"NO");
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(10, 10, 200, 50);
    button.backgroundColor = [UIColor greenColor];
    [touchView addSubview:button];
    [button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    // 2 . button的点击方法如何实现
    //   button 点击效果 , 通过UIResponder对应的方法实现的touch方法
    
    // 3 .  pointInside重写, 实现失去响应能力(return No)
}
- (void)buttonClicked:(UIButton *)button
{
    NSLog(@"############");
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [super touchesBegan:touches withEvent:event];
    NSLog(@"%@---------%s", [self class], __FUNCTION__);
}


//- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
//{
//    NSLog(@"%@---------%s", [self class], __FUNCTION__);
//}
//
//
//-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
//{
//    NSLog(@"%@---------%s", [self class], __FUNCTION__);
//}
//
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
